<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="9">
          <!-- 搜索输入框 -->
          <div>
            <el-input
              placeholder="请输入内容"
              :clearable="true"
              v-model="queryInfo.query"
              @clear="getOrderList()"
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="getOrderList()"
              ></el-button>
            </el-input>
          </div>
        </el-col>
      </el-row>
      <!-- 商品表单数据 -->
      <el-table
        style="width: 100%"
        :border="true"
        :stripe="true"
        :data="ordersList"
      >
        <el-table-column label="#" width="50" type="index"> </el-table-column>
        <el-table-column label="订单编号" width="900" prop="order_number">
        </el-table-column>
        <el-table-column label="订单价格" width="100" prop="order_price">
        </el-table-column>
        <el-table-column label="是否付款" width="100" prop="pay_status">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status == 0"
              >未付款</el-tag
            >
            <el-tag v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" width="100" prop="is_send">
        </el-table-column>
        <el-table-column label="下单时间" width="180" prop="create_time">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button type="primary" icon="el-icon-edit"></el-button>

            <el-button type="danger" icon="el-icon-location"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[2, 5, 10, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //订单列表
      ordersList: [],
      total: 0,
      //获取订单列表请求参数
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    //发送获取订单列表请求
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo,
      });
      if (res.meta.status !== 200)
        return this.$message.error("获取订单列表失败");
      this.total = res.data.total;
      this.ordersList = res.data.goods;
    },
    //改变没页个数
    handleSizeChange(newsize) {
      this.queryInfo.pagesize = newsize;
      this.getOrderList();
    },
    //改变页数
    handleCurrentChange(newpage) {
      this.queryInfo.pagenum = newpage;
      this.getOrderList();
    },
  },
};
</script>
<style lang='less' scoped>
</style>